package com.woniu.user.mapper;

import com.woniu.user.VO.PersonalInformationVO;
import com.woniu.user.pojo.*;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultType;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 * 用户端用户表 Mapper 接口
 * </p>
 *
 * @author LiFangyu
 * @since 2023-02-15
 */
public interface UserMapper extends BaseMapper<User> {

    @Select("select * from t_user where phone = #{phone} and password = #{password} and is_deleted = 0")
    User login(@Param("phone") String phone, @Param("password") String password);

    @Select("select * from t_user where phone = #{phone} and is_deleted = 1")
    User registerCheckExist(String phone);

    @Select("select * from t_user where phone = #{phone} and is_deleted = 0")
    User registerExist(String phone);

    @Select("select * from t_user where phone = #{phone} and is_deleted = 0")
    User selectByPhone(String phone);


    PersonalInformationVO personalInformation(String id);

    @Select("SELECT * FROM t_user WHERE id in (SELECT subscribe FROM t_fans WHERE be_subscribe = #{id} and is_deleted = 0) and is_deleted = 0")
    List<User> getAttention(String id);

    @Select("SELECT * FROM t_user WHERE id in (SELECT be_subscribe FROM t_fans WHERE subscribe = #{id} and is_deleted = 0) and is_deleted = 0")
    List<User> getFans(String id);

    @Select("SELECT * FROM t_article WHERE id in (SELECT article_id FROM t_user_article_collection WHERE user_id = #{id} and is_deleted = 0) and is_deleted = 0")
    List<Article> getCollect(String id);

    @Update("update t_user set portrait = #{uuid} where phone = #{phone} and is_deleted = 0")
    int setPortrait(@Param("phone") String phone, @Param("uuid") String uuid);

    @Select("SELECT * FROM t_car_circle where id = (select car_circle_id from  t_user_circle where user_id = #{id} and is_deleted = 0) and is_deleted = 0")
    UserCircle getUserCircle(String id);


    @Select("SELECT * FROM t_car_params WHERE id in (SELECT car_id FROM t_user_like_car WHERE user_id = #{id} and is_deleted = 0) and is_deleted = 0")
    List<CarParams> getUserLikeCar(String id);

    @Select("SELECT * from t_user_car WHERE user_id = #{id} and is_deleted = 0")
    List<UserCar> getUserCar(String id);
}
